package com.deli.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;

/**
 * 获取access_token
 */


@RestController
public class CommonController {

    private static final Logger logger = LoggerFactory.getLogger(CommonController.class);

    private String CORPID="ww76673d8a0d7cd9d7";

    private String CORPSECRET="3435ec7044408267d27512f76b6147d7";

    /**
     * 从redis中获取token
     * @return
     */
    @RequestMapping(value = "common/token")
    public String getToken() {
        String accessToken=null;
        Jedis jedis = new Jedis("127.0.0.1");
         accessToken = jedis.get("access_token");
        if (StringUtils.isNotBlank(accessToken)){
            return accessToken;
        }
        //todo
        //调用接口获取accessToken；
        String result ="" ;
        JSONObject jsonObject = JSON.parseObject(result);
        accessToken = jsonObject.getString("access_token");
        jedis.setex("access_token",7200,accessToken);
        return accessToken;
    }


}

